﻿namespace demo23_二维数组
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //1.创建方式 
            int[,] a; //1+n 加一个逗号 1+1=2维
            //type [ , , , ] arrayName;
            //二维数组可以看作表格
            a = new int[4, 4]; //2个长度 4*4表格


            //2.创建方式2
            int[,] b = new int[4, 4];


            //3.创建方式3
            int[,] c = new int[2, 2] { { 1, 1 }, { 2, 2 } };


            //4.创建方式4
            int[,] d = new int[,] { { 1, 1 }, { 2, 2 } };

            int[,] d2 = new int[,] { { 1, 1, 2 }, { 2, 2, 3 } };


            //5.
            int[,] f = { { 1, 1 }, { 2, 2 } };

            //int[,] a1 = new int[2, 2];
            //Console.WriteLine(a1[0, 0]);
            //Console.WriteLine(a1[0, 1]);
            //Console.WriteLine(a1[1, 0]);
            //Console.WriteLine(a1[1, 1]);


            //int[,] a2 = new int[2, 2] { { 1, 2 }, { 3, 4 } };
            ////Console.WriteLine(a2.Length);
            ////遍历
            //for(int i = 0;i < 2; i++)
            //{
            //    //Console.WriteLine(a[i,j]);
            //    //列
            //    for(int j = 0;j < 2; j++)
            //    {
            //        Console.WriteLine(a2[i, j]);
            //    }
            //}


            //遍历最后一行
            int[,] a3 = { { 1, 2 ,4}, { 3, 4 ,7}, { 3, 7, 7 } };
            //遍历
            int i2, k = 2;
            for (i2 = 0; i2 < 3; i2++)
                Console.WriteLine("{0}", a3[k,i2]); //a3[2,0]  a3[2,1]  a3[2,2]

            //随机数
            //1.创建random对象
            Random r = new Random();
            int c1 = r.Next();//生成随机数
            Console.WriteLine(c1);
            int c2 = r.Next(10);
            Console.WriteLine(c2);
            int c3 = r.Next(1,101);  //1-100  1---101-1
            Console.WriteLine(c3);

            int c4 = Random.Shared.Next(10, 20);
            Console.WriteLine(c4);




        }
    }
}
